package com.iflytek.uoamp.agent.monitor.sender.config;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class Config implements Cloneable {

	private static final Integer DEFAULT_BATCH_SIZE = 100;
	private static final long DEFAULT_CONNECT_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.convert(20, TimeUnit.SECONDS);
	private static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.convert(20, TimeUnit.SECONDS);
	private static final String LOG = "errLogger";
	private static final String CACHE = "logcalLogger";

	private String configFile;
	private boolean isUseHttp;

	private List<HostInfo> hostinfos = null; // flume host list
	private String cachePath;

	private int pingTimeOut = 0;
	private int noTranferFillPercentage = 0;
	private int connectPoolSize = 0; // connectPoolSize
	private int connectTimeOut = 0; // flume connect timeout
	private int requestTimeOut = 0; // flume request timeout
	private int schedualIntervalTime = 0;
	private int firstIntervalDelay = 0;
	private int sendQueueSize = 0;
	private int pingIntervalTime = 0;
	private boolean useSafeMod = true;
	private String url;

	
	public Config() {
		hostinfos = new ArrayList<HostInfo>();
		noTranferFillPercentage = 50;
		schedualIntervalTime = 300;
		firstIntervalDelay = 300;
		connectPoolSize = 10;
		pingTimeOut = 15000;
		pingIntervalTime = 3000;
		connectTimeOut = 20000;
		requestTimeOut = 20000;
		useSafeMod = false;
	}


	public static Integer getDefaultBatchSize() {
		return DEFAULT_BATCH_SIZE;
	}


	public static long getDefaultConnectTimeoutMillis() {
		return DEFAULT_CONNECT_TIMEOUT_MILLIS;
	}


	public static long getDefaultRequestTimeoutMillis() {
		return DEFAULT_REQUEST_TIMEOUT_MILLIS;
	}


	public static String getLog() {
		return LOG;
	}


	public static String getCache() {
		return CACHE;
	}


	public String getConfigFile() {
		return configFile;
	}

	public void setConfigFile(String configFile) {
		this.configFile = configFile;
	}
	
	public String getCachePath() {
		return cachePath;
	}

	public void setCachePath(String cachePath) {
		this.cachePath = cachePath;
	}

	public String getUrl() {
		if (url != null) {
			if (url.endsWith("/")) {
				return url.substring(0, url.length() - 1);
			} else {
				return url;
			}
		} else {
			return "http://127.0.0.1:8080";
		}
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public boolean isUseHttp() {
		return isUseHttp;
	}

	public void setUseHttp(boolean isUseHttp) {
		this.isUseHttp = isUseHttp;
	}

	@Override
	public Object clone() {
		Config config = null;
		try {
			config = (Config) super.clone();
		} catch (CloneNotSupportedException e) {
			Logger.getRootLogger().error(e.getMessage(),e);
		}
		return config;
	}

	
	public int getPingIntervalTime() {
		return pingIntervalTime;
	}

	public void setPingIntervalTime(int pingIntervalTime) {
		this.pingIntervalTime = pingIntervalTime;
	}

	public int getPingTimeOut() {
		return pingTimeOut;
	}

	public void setPingTimeOut(int pingTimeOut) {
		this.pingTimeOut = pingTimeOut;
	}

	public List<HostInfo> getHostInfo() {
		return this.hostinfos;
	}

	public void setHostInfo(List<HostInfo> hostinfos) {
		this.hostinfos = hostinfos;
	}

	public int getNoTranferFillPercentage() {
		return noTranferFillPercentage;
	}

	public void setNoTranferFillPercentage(int noTranferFillPercentage) {
		this.noTranferFillPercentage = noTranferFillPercentage;
	}

	public int getConnectPoolSize() {
		return this.connectPoolSize;
	}

	public void setConnectPoolSize(int connectPoolSize) {
		this.connectPoolSize = connectPoolSize;
	}

	public int getConnectTimeOut() {
		return connectTimeOut;
	}

	public void setConnectTimeOut(int connectTimeOut) {
		this.connectTimeOut = connectTimeOut;
	}

	public int getRequestTimeOut() {
		return this.requestTimeOut;
	}

	public int getFirstIntervalDelay() {
		return firstIntervalDelay;
	}

	public void setFirstIntervalDelay(int firstIntervalDelay) {
		this.firstIntervalDelay = firstIntervalDelay;
	}

	public void setRequestTimeOut(int requestTimeOut) {
		this.requestTimeOut = requestTimeOut;
	}

	public int getSendQueueSize() {
		return sendQueueSize;
	}

	public boolean isUseSafeMod() {
		return useSafeMod;
	}

	public void setSendQueueSize(int sendQueueSize) {
		this.sendQueueSize = sendQueueSize;
	}

	public void setIsUseSafeMod(boolean isUseSafeMod) {
		this.useSafeMod = isUseSafeMod;
	}

	public int getSchedualIntervalTime() {
		return schedualIntervalTime;
	}

	public void setSchedualIntervalTime(int schedualIntervalTime) {
		this.schedualIntervalTime = schedualIntervalTime;
	}
}
